#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n), pre(n + 1);
    for(int i = 0; i < n; i++) cin >> a[i], pre[i + 1] = pre[i] + a[i];
    ll ans = 0;
    auto check = [&](int x)->ll {
        vector<ll> vec;
        for(int i = x; i <= n; i += x){
            vec.push_back(pre[i] - pre[i - x]);
        }
        return *max_element(vec.begin(), vec.end()) - *min_element(vec.begin(), vec.end());
    };
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            int p = n / i;
            ans = max({ans, check(p), check(i)});
        }
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--) solve();
    return 0;
}